package tk.mystudio.web.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

import tk.mystudio.permission.bean.Resource;
import tk.mystudio.permission.service.ResourceService;
import tk.mystudio.util.Order;
import tk.mystudio.util.Page;

public class ResourceAction extends CommonAction<Resource> {
	@Autowired
	private ResourceService resourceService;

	private Resource resource;

	public String search() {
		List<Order> orders = new ArrayList<Order>();
		if (StringUtils.hasText(sortField)) {
			if ("asc".equalsIgnoreCase(order)) {
				orders.add(Order.asend(sortField));
			} else {
				orders.add(Order.descend(sortField));
			}
		}
		page = resourceService.listByPage(resource, new Page<Resource>(
				currentPage, pageSize),
				orders.toArray(new Order[orders.size()]));
		return LIST;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	public Resource getResource() {
		return resource;
	}

	public void setResource(Resource resource) {
		this.resource = resource;
	}

	@Override
	public Page<Resource> getPage() {
		return page;
	}
}
